var layerId;
var clickState = true;
$(function(){
	$("#save-button").click(function(){
		var name = $("input[name='name']").val();
		var discount = $("input[name='discount']").val();
		var isDefault = $("input[name='isDefault']:checked").val();
		if(name.length == 0){
			layer.msg("请输入等级名称");
			return false;
		}
		if(discount.length == 0){
			layer.msg("请输入折扣");
			return false;
		}
		discount = Number(discount);
		console.log(!isNum(discount));
		console.log(discount<1);
		console.log(discount>100);
		if((!isNum(discount))|| discount<1 || discount>100){
			layer.msg("折扣为1-100之间的整数");
			return false;
		}
		var gradeId=init.gradeId;
		var grade ={
			"id":gradeId,
			"name":name,
			"discount":discount,
			"isDefault":isDefault
		}
		if(clickState){
			clickState = false;
			$.ajax({
				url:basePath+"/userGrade/save.shtml",
				data:grade,
				type:"post",
				dataType:"JSON",
				success:ajaxSuccessCloseFun
			});
		}
	});
	$("#close-button").click(function(){
		parent.closeLayer(0);
	});
	
});